<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
</head>
<body>
	<div id="moduleHtml">
	 <div id="titlebarContainter">
		  <div id="titlebarStart">Coffee Desk</div>
		  <div id="titlebarSearch"></div>
		  <div id="titlebarUser">
		    <span id="username"></span>已经登录
		    <div>
			    <div id="changeName">修改用户名</div>
			    <div id="changePwd">修改密码</div>
			    <div id="exitSystem">退出</div>
		    </div>
		  </div>
	  </div>
	</div>
</body>
  <script>
  //cofit_module_js
    Cofit.moduleSourceCode.title_bar=function(dom){
      var module = {
        dom : $(dom) ,        
        //显示
        show : function(){
	          var dom=$(module.dom);
	          $("body").append(dom);
	          $(window).resize(module.resize);
	          var containter=dom.find("#titlebarContainter");
	          containter.css("top",-containter.height()+"px");
	          module.resize();
	          
	          $.get("./dict/get_dict_by_code/username",{},function(resp){
	        	  	          $("#username").html(resp);
	          });
	          
	          $("#exitSystem").linkbutton();
	          $("#exitSystem").click(function(){
	        	  location.reload();
	          });
	          $("#changeName").linkbutton();
	          $("#changeName").click(function(){
	        	  $.messager.prompt("修改用户名","请输入新的用户名：",function(input){
	        		  if(null!=input){
	        			  $.post("./dict/change_username",{
	        				  username : input ,
	        			  },function(resp){
	        				  if(resp.success){
	        					  $.messager.show({
	        						  msg : "修改用户名成功！",
	        					  });
	        				  }
	        				  
	        				  
	        				   $.get("./dict/get_dict_by_code/username",{},function(resp){
	                               $("#username").html(resp);
	                 });
	        				  
	        			  },"json");
	        		  }
	        	  });
	          });	          
	          $("#changePwd").linkbutton();
	          $("#changePwd").click(function(){
	        	  $.messager.prompt("修改密码","请输入旧密码：",function(oldInput){
	        		  if(null!=oldInput){
	        			  $.messager.prompt("修改密码","请输入新密码：",function(newInput){
	        				  $.post("./dict/change_pwd",{
	        					  oldpwd : oldInput ,
	        					  newpwd : newInput ,
	        				  },function(resp){
	        					  console.dir(resp)
	        					  if(resp.success){
	        						  $.messager.show({
	        							  msg : "修改密码成功！" ,
	        						  });
	        					  }else{
	        						  $.messager.alert("修改密码",resp.msg,"error");
	        					  }
	        				  });
	        			  });
	        		  }
	        	  });
	          });
	          
	          
	          containter.animate( { top: 0}, "slow",function(){
	        	  module.resize();
	        	    Cofit.load("side_bar",function(module){
	        	        module.show();
	        	      });
         	  });
        },
        //跟随窗口尺寸        
        resize : function(){
          var dom=$(module.dom);
          var containter=dom.find("#titlebarContainter");
          containter.width( $(window).width() );
          var searchWidth=$(window).width()-
	          dom.find("#titlebarStart").width()-
	          dom.find("#titlebarUser").width();
          dom.find("#titlebarSearch").width(searchWidth);
        }
      };
      return module;
    };
  //cofit_module_js
  </script>
</html>